package cn.edu.zafu.bigdata.x.XuShuXinPR.XsxGusessNumber;
import java.util.Random;
import java.util.Scanner;

public class XsxGuessNum {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        boolean playAgain = true;

        while (playAgain) {
            int numberToGuess = random.nextInt(100) + 1; // 随机生成1到100之间的数字
            int maxAttempts = 10; // 最大尝试次数
            int attempts = 0;
            boolean hasWon = false;

            System.out.println("欢迎来到猜数字游戏！你有 " + maxAttempts + " 次机会猜中一个1到100之间的数字。");

            while (attempts < maxAttempts) {
                System.out.print("请输入你的猜测：");
                int guess = scanner.nextInt();
                attempts++;

                if (guess < numberToGuess) {
                    System.out.println("太小了！");
                } else if (guess > numberToGuess) {
                    System.out.println("太大了！");
                } else {
                    hasWon = true;
                    break;
                }
            }

            if (hasWon) {
                System.out.println("恭喜你！你在 " + attempts + " 次尝试中猜中了数字 " + numberToGuess + "！");
            } else {
                System.out.println("很遗憾，你没有在 " + maxAttempts + " 次尝试中猜中数字。正确的数字是 " + numberToGuess + "。");
            }

            System.out.print("你想再玩一次吗？(yes/no)：");
            playAgain = scanner.next().equalsIgnoreCase("yes");
        }

        System.out.println("感谢你的游戏，再见！");
        scanner.close();
    }
}
